import Vue from 'vue'
import App from './App.vue'
import router from './router'
import { getToken } from '@/utils/storage'
import { Cell, CellGroup, Toast, Search, Form, Field, Button, NavBar, Tabbar, TabbarItem, Image as VanImage, Grid, GridItem, List, Icon, Empty, Swipe, SwipeItem, Lazyload, IndexBar, IndexAnchor, Popup, Uploader, Picker } from 'vant'

Vue.use(Picker)
Vue.use(Uploader)
Vue.use(Popup)
Vue.use(IndexBar)
Vue.use(Cell)
Vue.use(CellGroup)
Vue.use(IndexAnchor)
Vue.use(Lazyload)
Vue.use(Swipe)
Vue.use(SwipeItem)
Vue.use(Search)
Vue.use(List)
Vue.use(Icon)
Vue.use(Grid)
Vue.use(GridItem)
Vue.use(VanImage)
Vue.use(Tabbar)
Vue.use(TabbarItem)
Vue.use(NavBar)
Vue.use(Button)
Vue.use(Form)
Vue.use(Field)
Vue.use(Toast)
Vue.use(Empty)

Vue.config.productionTip = false

// 全局路由守卫
const WhiteList = ['/login', '/register'] // 白名单
router.beforeEach((to, from, next) => {
  const token = getToken()
  if (token) {
    next()
  } else {
    if (WhiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})

new Vue({
  router,
  render: (h) => h(App)
}).$mount('#app')
